/*
 * Copyright (c) 2023. All rights reserved.
 * Please don't try to modify the code, because I don't know what the consequences will be.
 *
 *
 *
 *
 *
 *
 *
 */

package cc.zzone.bean;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * RestController拦截器
 *
 * @author jinzhengze
 * @since 2022年9月7日
 */
@Slf4j
@RestControllerAdvice
@Order(Integer.MIN_VALUE)
public class GlobalControllerAdvice {

    @Value("${spring.application.name:service name not found}")
    private String serviceName;

    /**
     * 全局异常拦截并返回错误响应
     */
    @ExceptionHandler(Exception.class)
    public Object catchException(Exception e) {
        log.error("Error : " + e);
        return Result.fail(serviceName.toUpperCase() + " : " + e.getMessage());
    }
}
